﻿using System;
using System.Data;
using System.Web.UI.WebControls;
using WorkOrder.Business;

namespace WorkOrder.workBill
{
    public partial class queryTimeByStep : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null || Session["UserID"].ToString() == "")
            {
                Session.Clear();
                ClientScript.RegisterClientScriptBlock(this.GetType(), "windowhref", "<script type='text/javascript'>alert('对不起，您还没有登录系统！');window.parent.location.href='../login.aspx';</script>");
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (txtSTART_DATE.Value.Trim() == "")
            {
                lblMsg.Text = "请输入开始时间！";
                return;
            }
            if (txtEND_DATE.Value.Trim() == "")
            {
                lblMsg.Text = "请输入结束时间！";
                return;
            }
            if (!Radio1.Checked && !Radio2.Checked && !Radio3.Checked)
            {
                lblMsg.Text = "请选择一种查询说明！";
                return;
            }
            /**
             * 查询说明：
             * ０：分析此时间范围内所有已归档的主单的所有环节的平均时长，各环节点时间不受此范围限制
             * １：分析此时间范围内所有已归档的主单，并在此时间范围内的所有环节的平均时长，各环节点时间受此时间范围限制
             * ２：分析此时间范围内所有环节的平均时长，仅各环节点时间受此时间范围限制
             */
            int tmp = 3;
            if (Radio1.Checked) tmp = 0; else if (Radio2.Checked) tmp = 1; else if (Radio3.Checked) tmp = 2;
            hiddenDesc.Value = tmp.ToString();

            lblMsg.Text = "";
            AvgTimeLength atl = new AvgTimeLength();
            //语音-开通-GPON
            DataTable tmpTable = atl.queryAvgTimeLengthByStep("1", "1", "GPON接入", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView1.DataSource = tmpTable;
                GridView1.DataBind();
            }

            //数据-开通-GPON
            tmpTable = atl.queryAvgTimeLengthByStep("2", "1", "GPON接入", txtSTART_DATE.Value.Trim(),
                                                    txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView2.DataSource = tmpTable;
                GridView2.DataBind();
            }

            //语音-开通-传统
            tmpTable = atl.queryAvgTimeLengthByStep("1", "1", "传统方式接入", txtSTART_DATE.Value.Trim(),
                                                    txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView3.DataSource = tmpTable;
                GridView3.DataBind();
            }

            //数据-开通-传统
            tmpTable = atl.queryAvgTimeLengthByStep("2", "1", "传统方式接入", txtSTART_DATE.Value.Trim(),
                                                    txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView4.DataSource = tmpTable;
                GridView4.DataBind();
            }

            //语音-调整
            tmpTable = atl.queryAvgTimeLengthByStep("1", "3", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView5.DataSource = tmpTable;
                GridView5.DataBind();
            }

            //语音-取消
            tmpTable = atl.queryAvgTimeLengthByStep("1", "2", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView6.DataSource = tmpTable;
                GridView6.DataBind();
            }

            //数据-调整
            tmpTable = atl.queryAvgTimeLengthByStep("2", "3", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView7.DataSource = tmpTable;
                GridView7.DataBind();
            }

            //数据-取消
            tmpTable = atl.queryAvgTimeLengthByStep("2", "2", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView8.DataSource = tmpTable;
                GridView8.DataBind();
            }

            //电路租用-开通
            tmpTable = atl.queryAvgTimeLengthByStep("4", "1", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView9.DataSource = tmpTable;
                GridView9.DataBind();
            }

            //电路租用-调整
            tmpTable = atl.queryAvgTimeLengthByStep("4", "3", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView11.DataSource = tmpTable;
                GridView11.DataBind();
            }

            //电路租用-取消
            tmpTable = atl.queryAvgTimeLengthByStep("4", "2", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView13.DataSource = tmpTable;
                GridView13.DataBind();
            }

            //GPRS-开通
            tmpTable = atl.queryAvgTimeLengthByStep("5", "1", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView10.DataSource = tmpTable;
                GridView10.DataBind();
            }

            //GPRS-调整
            tmpTable = atl.queryAvgTimeLengthByStep("5", "3", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView12.DataSource = tmpTable;
                GridView12.DataBind();
            }

            //GPRS-取消
            tmpTable = atl.queryAvgTimeLengthByStep("5", "2", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView14.DataSource = tmpTable;
                GridView14.DataBind();
            }

            //企业信息机-开通
            tmpTable = atl.queryAvgTimeLengthByStep("3", "1", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView15.DataSource = tmpTable;
                GridView15.DataBind();
            }

            //企业信息机-调整
            tmpTable = atl.queryAvgTimeLengthByStep("3", "3", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView17.DataSource = tmpTable;
                GridView17.DataBind();
            }

            //企业信息机-取消
            tmpTable = atl.queryAvgTimeLengthByStep("3", "2", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView19.DataSource = tmpTable;
                GridView19.DataBind();
            }

            //短信直连-开通
            tmpTable = atl.queryAvgTimeLengthByStep("6", "1", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView16.DataSource = tmpTable;
                GridView16.DataBind();
            }

            //短信直连-调整
            tmpTable = atl.queryAvgTimeLengthByStep("6", "3", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView18.DataSource = tmpTable;
                GridView18.DataBind();
            }

            //短信直连-取消
            tmpTable = atl.queryAvgTimeLengthByStep("6", "2", "", txtSTART_DATE.Value.Trim(), txtEND_DATE.Value.Trim(), tmp);
            if (tmpTable != null)
            {
                GridView20.DataSource = tmpTable;
                GridView20.DataBind();
            }
            if (tmpTable != null) tmpTable.Dispose();
            lblMsg.Text = "";
        }

        protected void gvReport_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex >= 0)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor,this.style.background='#ffe3a0'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#fff'");
            }
        }
    }
}